<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>mms-computing : package scanner provides combined java twain & sane wrapper (windows, linux)</title>
<meta name="keywords" content="java, twain, jtwain, SANE, jsane">
<meta name="description" content="Package scanner provides abstract parent classes to the classes in the <i>twain</i> and <i>sane</i> packages.">
<link rel=StyleSheet href="../../../../../css/general.css" type="text/css" title="mmsc-style" media="screen">
<link rel=StyleSheet href="../../../../../css/print.css" type="text/css" title="mmsc-style" media="print">
</head>
<body>
<div id="container">
<div id="header"><FONT COLOR="#0000ff">m</FONT><FONT COLOR="#ff0000">m</FONT>'<FONT COLOR="#7bc618">s</FONT> <FONT COLOR="#ffff00">c</FONT>omputing</div>
<div id="menu">
<ul>
<li><a href="../../../../../index.html">home</a></li>
<li><a href="../../../../../uk/co/mmscomputing/news/index.html">news</a></li>
<li><a href="../../../../../uk/co/mmscomputing/download/index.html">download</a></li>
<li><a href="../../../../../uk/co/mmscomputing/donation/index.html">donation</a></li>
<li><a href="../../../../../uk/co/mmscomputing/contact/index.html">contact</a></li>
</ul>
</div>
<div id="nav">&nbsp;
<div class="roundrect">
<div class="roundrect-top"><div></div></div>
<div class="roundrect-left"><div class="roundrect-right">
<div class="roundrect-gradient"><b>sub-directories</b></div>
<ul>
<li><a href="../index.html">up</a></li>
</ul>
</div></div>
<div class="roundrect-bottom"><div></div></div>
</div>
</div>
<div id="content">
<div id="abstract">
Package scanner provides abstract parent classes to the classes in the <i>twain</i> and <i>sane</i> packages.
</div>
<div id="desc">
<p>The following is what you need to put into your code.
<br>If class Scanner has found & could load either the twain (32bit Windows) or sane (Linux) library,
then it will return a scanner object.
<br>If you want the scanner object to signal events to certain classes/objects then you need to implement the
ScannerListener interface: 
<br><br><nobr><em class="remark">public void update(ScannerIOMetadata.Type type, ScannerIOMetadata metadata)</em></nobr>
<br><br>and you need to add the listening objects to the scanners listener list:
<br><br><nobr><em class="remark">scanner.addListener(object);</em></nobr>

<br><br>An excerpt from the <i>imageviewer</i> project:

<br>
<p><pre class="remark">

  package uk.co.mmscomputing.application.imageviewer;

  public class ScannerTab extends JPanel implements ScannerListener{

    Scanner scanner=null;

    public ScannerTab(){
      .
      .
      .

      scanner=Scanner.getDevice();
      if(scanner!=null){
        scanner.addListener(this);
        add(scanner.getScanGUI());
      }

      .
      .
      .
    }

    public void update(ScannerIOMetadata.Type type, ScannerIOMetadata metadata){
      if(type.equals(ScannerIOMetadata.ACQUIRED)){
        BufferedImage img=metadata.getImage();             // acquired image as BufferedImage
        .
        .  do what you have to do
        .
      }else if(type.equals(ScannerIOMetadata.FILE)){  
        File file=metadata.getFile();                      // acquired image as file (twain only for the time being)
        .
        .  do what you have to do
        .
      }else if(type.equals(ScannerIOMetadata.NEGOTIATE)){  // (twain only in the moment)
        .
        .  negotiate default settings
        .
      }else if(type.equals(ScannerIOMetadata.STATECHANGE)){
        switch(metadata.getState()){
        .
        .  do what you have to do
        .
        }
        System.out.println("Scanner State "+metadata.getStateStr());
      }else if(type.equals(ScannerIOMetadata.INFO)){
        System.out.println(metadata.getInfo());
      }else if(type.equals(ScannerIOMetadata.EXCEPTION)){
        System.out.println(metadata.getException());
      }
    }
  }

  public void stop(){                                                    // execute before System.exit
    if(scanner!=null){                                                   // make sure user waits for scanner to finish!
      scanner.waitForNotBusy();
    }
  }

</pre></p>
</p></div>
<div id="files">
Package : uk.co.mmscomputing.device.scanner
<ol>
<li><a href="Scanner.java">Scanner.java</a></li>
<li><a href="ScannerDevice.java">ScannerDevice.java</a></li>
<li><a href="ScannerIOException.java">ScannerIOException.java</a></li>
<li><a href="ScannerIOMetadata.java">ScannerIOMetadata.java</a></li>
<li><a href="ScannerListener.java">ScannerListener.java</a></li>
<li><a href="uk.co.mmscomputing.device.scanner.jar">uk.co.mmscomputing.device.scanner.jar</a></li>
</ol>
</div>
<div id="dirlist">
</div>
<div id="projects">
Projects :
<ol>
<li><a href="../../../../../uk/co/mmscomputing/application/imageviewer/index.html">uk.co.mmscomputing.application.imageviewer</a>:
<br>A simple Multi Page Image Viewer Applet. To view multipage *.sff, *.tiff and *.gif files. Twain and SANE test application.
</li>
<li><a href="../../../../../uk/co/mmscomputing/device/sane/index.html">uk.co.mmscomputing.device.sane</a>:
<br>This open source software project connects the world of java with SANE.SANE is an application programming interface standard used to access scanners &amp; digital cameras ... .This project consists of a SANE frontend written in java.
</li>
<li><a href="../../../../../uk/co/mmscomputing/device/twain/index.html">uk.co.mmscomputing.device.twain</a>:
<br>This open source software project connects the world of java with TWAIN.TWAIN is an application programming interface standard used to access scanners &amp; digital cameras ... .
</li>
</ol>
</div>
</div>
<div id="fcontainer">
<div id="gnu">
All software on this site is free software; you can redistribute it and/or modify it under the terms of the <a href="http://www.gnu.org/copyleft/lesser.html" target="_blank"> GNU Lesser General Public License </a> as published by the Free Software Foundation
</div>
<div id="footer">
<br><FONT COLOR="#0000ff">m</FONT><FONT COLOR="#ff0000">m</FONT>'<FONT COLOR="#7bc618">s</FONT> <FONT COLOR="#ffff00">c</FONT>omputing<br>2010-03-04
</div>
</div>
</div>
</body>
</html>
